﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;

namespace HadronData
{
    public class Ray
    {
        private Vector2 m_vecSource, m_vecDirection;

        public Ray()
        {
            m_vecSource = Vector2.Zero;
            m_vecDirection = Vector2.UnitX;
        }

        public Ray(Vector2 p_vecSource, Vector2 p_vecDirection)
        {
            m_vecSource = p_vecSource;
            m_vecDirection = p_vecDirection;
            m_vecDirection.Normalize();
        }

        public float GetSignedTangentDistance(Vector2 p_vecPoint)
        {
            return Vector2.Dot(p_vecPoint - m_vecSource, m_vecDirection);
        }

        public void Transform(Transformation p_transformation)
        {
            m_vecSource = p_transformation.Apply(m_vecSource);
            m_vecDirection = p_transformation.RotationComponent.Apply(m_vecDirection);
        }

        public Ray TransformCopy(Transformation p_transformation)
        {
            return new Ray(
                p_transformation.Apply(m_vecSource),
                p_transformation.RotationComponent.Apply(m_vecDirection)); 
        }

        public Vector2 Source
        {
            get { return m_vecSource; }
            set { m_vecSource = value; }
        }

        public Vector2 Direction
        {
            get { return m_vecDirection; }
            set
            {
                m_vecDirection = value;
                m_vecDirection.Normalize();
            }
        }

    }
}
